<?php
namespace TestHome\Controller;
use Think\Controller;
class MyQuizController extends BaseController {

    private  function checkVisible()
    {
        $is_visible =  M("orgnizer_grouptest")
            ->join("orgnizer_userquizlist on orgnizer_grouptest.testgroup_id = orgnizer_userquizlist.testgroup_id")
            ->where(["orgnizer_userquizlist.uid" => parent::$uid])->select();

        if ($is_visible){
            if($is_visible[0]['isvisible'] == 0){
                echo "暂时还不能看这个报告哦";
                exit;
            }
        }
    }


    public function getReportList()
    {
        $rs = M("calc_result")->where(['user_id' => parent::$uid])
            ->join("quiz_info on quiz_info.quiz_id = calc_result.quiz_id")
            ->group('calc_result.quiz_id')
            ->field("calc_result.quiz_id, quiz_info.quiz_name, quiz_info.quiz_pagetitle")
            ->select();

        $this->ajaxReturn($rs);


        //var_dump($rs);
    }

    public function showReport($quiz_name)
    {
        $this->checkVisible();
        if($quiz_name == 'wippf_demo'){
            $ctl = A("Quiz/Wippf");
            $ctl->show_wippf(parent::$uid);
        }
        else if($quiz_name == '16pf_test'){
            $ctl = A("Quiz/Pf16");
            $ctl->show_16pf(parent::$uid);
        }

        else if($quiz_name == 'mbti'){
            $ctl = A("Quiz/Mbti");
            $ctl->show_mbti(parent::$uid);
        }

        else{
            $ctl = A("Quiz/CustomQuiz");
            $ctl->show_report(convertToQuizId($quiz_name) ,"count", parent::$uid);
        }

    }

    public function index()
    {
        //显示导入的问卷列表
        $rs = M("quiz_info")->where("quiz_id > 12")->select();
        $this->assign("quiz_list", $rs);
        $this->display();
        //var_dump($rs);
    }

    public function show_sample($quiz_id)
    {
        if($quiz_id == 6){
            $ctl = A("Quiz/Pf16");
            $ctl->pf16_sample();
        }
        else if($quiz_id == 7){
            $ctl = A("Quiz/Wippf");
            $ctl->wippf_sample();
        }
        else if($quiz_id == 12){
            $ctl = A("Quiz/Mbti");
            $ctl->mbti_sample();
        }
        else if($quiz_id == 14){
            $ctl = A("Quiz/CustomQuiz");
            $ctl->disc_sample();
        }
    }

//    public function show_16pf()
//    {
//        $ctl = A("Type16pf");
//        //var_dump(parent::$uid);
//        $result = $ctl->show_16pf(parent::$uid);
//
//        $this->assign("result", $result);
//        $this->display("Type16pf:show_16pf");
//    }
//
//    public function show_wippf()
//    {
//        $this->checkVisible();
//
//
//        $ctl = A("Quiz/Wippf");
//        $ctl->show_wippf(parent::$uid);
//    }

//    public function index()
//    {
//        $this->assign('userinfo', parent::$userinfo);
//        $this->display();
//    }

    public function MyReport()
    {
        $this->assign('userinfo', parent::$userinfo);
        $this->display();
    }

    public function downloadPdf()
    {
        $ctl = A("OutputFile");
        $ctl->out16pfReport(parent::$uid);
    }

}